home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fips11.zip / SOURCE / GLOBAL.CPP < prev    next >
C/C++ Source or Header  |  1994-05-25  |  7KB  |  228 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module global.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/global.cpp 1.1 1994/05/25 22:19:49 schaefer Exp schaefer $
  8.  
  9.     Copyright (C) 1993 Arno Schaefer
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  
  26.     Report problems and direct all questions to:
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de
  29. */
  30.  
  31. #include <stdarg.h>
  32. #include <conio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include "global.h"
  36.  
  37. #define CTRL_C 3
  38.  
  39. global_vars global;
  40.  
  41. /* ----------------------------------------------------------------------- */
  42. /* Initialization of global variables                                      */
  43. /* ----------------------------------------------------------------------- */
  44.  
  45. global_vars::global_vars (void)
  46. {
  47.     test_mode = false;
  48.     verbose_mode = true;
  49.     debug_mode = false;
  50.  
  51.     override_multiple_boot = false;
  52.     override_bootable_flag = false;
  53.     override_rootdir_entries = false;
  54.     override_large_fat = false;
  55.     override_small_fat = false;
  56.     override_media_descriptor = false;
  57.  
  58.     drive_number_cmdline = 0;
  59.     partition_number_cmdline = 0;
  60.     new_start_cylinder_cmdline = 0;
  61. }
  62.  
  63. global_vars::~global_vars (void)
  64. {
  65.     if (debug_mode) fclose (debugfile);
  66. }
  67.  
  68. void exit_function (void)
  69. {
  70.     printx ("\nBye!\n");
  71. }
  72.  
  73. void global_vars::open_debugfile (int argc,char *argv[])
  74. {
  75.     if ((debugfile = fopen ("fipsinfo.dbg","wt")) == NULL)
  76.     {
  77.         global.debug_mode = false;
  78.         warning ("Can't open debugfile");
  79.     }
  80.     else
  81.     {
  82.         fprintf (debugfile,"FIPS Debug File\n\n");
  83.         fprintf (debugfile,"The command was: ");
  84.         while (argc--) fprintf (debugfile,argc ? "%s " : "%s", *argv++);
  85.         fprintf (debugfile,"\n\nTranscript of session:\n");
  86.     }
  87. }
  88.  
  89. /* ----------------------------------------------------------------------- */
  90. /* Replacement for printf - prints to screen and debugfile                 */
  91. /* ----------------------------------------------------------------------- */
  92.  
  93. void printx (char *fmt,...)
  94. {
  95.     va_list ap;
  96.     va_start (ap,fmt);
  97.     vprintf (fmt,ap);
  98.     if (global.debug_mode) vfprintf (global.debugfile,fmt,ap);
  99.     va_end (ap);
  100. }
  101.  
  102. /* ----------------------------------------------------------------------- */
  103. /* Replacement for getch - exit when CTRL-C is pressed                     */
  104. /* ----------------------------------------------------------------------- */
  105.  
  106. int getx (void)
  107. {
  108.     int character = getch();
  109.     if (character == CTRL_C)
  110.     {
  111.         printx ("\n");
  112.         exit (0);
  113.     }
  114.     return (character);
  115. }
  116.  
  117. /* ----------------------------------------------------------------------- */
  118. /* Copyright notice and version number                                     */
  119. /* ----------------------------------------------------------------------- */
  120.  
  121. void notice (void)
  122. {
  123.     printx ("\nFIPS version 1.1, Copyright (C) 1993/94 Arno Schaefer\n\n");
  124.     printx ("DO NOT use FIPS in a multitasking environment like Windows, OS/2, Desqview,\n");
  125.     printx ("Novell Task manager or the Linux DOS emulator: boot from a DOS boot disk first.\n\n");
  126.     printx ("If you use OS/2 or a disk compressor, read the relevant sections in FIPS.DOC.\n\n");
  127.     printx ("FIPS comes with ABSOLUTELY NO WARRANTY, see file COPYING for details\n");
  128.     printx ("This is free software, and you are welcome to redistribute it\n");
  129.     printx ("under certain conditions; again see file COPYING for details.\n");
  130.  
  131.     printx ("\nPress any Key\n");
  132.     getx();
  133. }
  134.  
  135. /* ----------------------------------------------------------------------- */
  136. /* Hexdump binary data into a file                                         */
  137. /* ----------------------------------------------------------------------- */
  138.  
  139. void hexwrite (byte *buffer,int number,FILE *file)
  140. {
  141.     for (int i=0;i<number;i++)
  142.     {
  143.         fprintf (file,"%02X ",*(buffer+i));
  144.         if ((i+1)%16 == 0) fprintf (file,"\n");
  145.         else if ((i+1)%8 == 0) fprintf (file,"- ");
  146.     }
  147.     fprintf (file,"\n");
  148. }
  149.  
  150. /* ----------------------------------------------------------------------- */
  151. /* Error Handling                                                          */
  152. /* ----------------------------------------------------------------------- */
  153.  
  154. static void print_verbose_message (char *message)
  155. {
  156.     char line[256];
  157.     int length = 0;
  158.     FILE *error_msg_file;
  159.  
  160.     fprintf (stderr,"\n");
  161.     if (global.debug_mode) fprintf (global.debugfile,"\n");
  162.  
  163.     if ((error_msg_file = fopen ("errors.txt","rt")) == NULL)
  164.     {
  165.         fprintf (stderr,"File ERRORS.TXT not found - no verbose messages available\n");
  166.         if (global.debug_mode) fprintf (global.debugfile,"File ERRORS.TXT not found - no verbose messages available\n");
  167.         global.verbose_mode = false;
  168.         return;
  169.     }
  170.  
  171.     while (message[length] != 0 && message[length] != ':') length++;
  172.  
  173.     fgets (line,255,error_msg_file);
  174.     while (strncmp(message,line,length)) if (fgets (line,255,error_msg_file) == NULL) return;
  175.     fgets (line,255,error_msg_file);
  176.     while (!strncmp("  ",line,2))
  177.     {
  178.         fprintf (stderr,"%s",line+2);
  179.         if (global.debug_mode) fprintf (global.debugfile,"%s",line+2);
  180.         if (fgets (line,255,error_msg_file) == NULL) return;
  181.     }
  182.     fclose (error_msg_file);
  183. }
  184.  
  185. void error (char *message,...)
  186. {
  187.     va_list ap;
  188.  
  189.     fprintf (stderr,"\nError: ");
  190.     if (global.debug_mode) fprintf (global.debugfile,"\nError: ");
  191.  
  192.     va_start (ap,message);
  193.     vfprintf (stderr,message,ap);
  194.     if (global.debug_mode) vfprintf (global.debugfile,message,ap);
  195.     va_end (ap);
  196.  
  197.     fprintf (stderr,"\n");
  198.     if (global.debug_mode) fprintf (global.debugfile,"\n");
  199.  
  200.     if (global.verbose_mode) print_verbose_message (message);
  201.  
  202.     exit (-1);
  203. }
  204.  
  205. void warning (char *message,...)
  206. {
  207.     va_list ap;
  208.  
  209.     fprintf (stderr,"\nWarning: ");
  210.     if (global.debug_mode) fprintf (global.debugfile,"\nWarning: ");
  211.  
  212.     va_start (ap,message);
  213.     vfprintf (stderr,message,ap);
  214.     if (global.debug_mode) vfprintf (global.debugfile,message,ap);
  215.     va_end (ap);
  216.  
  217.     fprintf (stderr,"\n");
  218.     if (global.debug_mode) fprintf (global.debugfile,"\n");
  219.  
  220.     if (global.verbose_mode) print_verbose_message (message);
  221.  
  222.     fprintf (stderr,"\nPress any key\n");
  223.     if (global.debug_mode) fprintf (global.debugfile,"\nPress any key\n");
  224.  
  225.     getx();
  226. }
  227.  
  228.